<template>
  <div 
    v-show="showButton" 
    class="floating-btn"
    :class="{ 'show' : showButton }"
    @click="scrollToTop"
  >
    <i class="fas fa-arrow-up"></i>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, onUnmounted } from 'vue'

// 控制按钮显示状态
const showButton = ref(false)

// 监听滚动事件
const handleScroll = () => {
  showButton.value = window.scrollY > 500
}

// 滚动到顶部
const scrollToTop = () => {
  window.scrollTo({
    top: 0,
    behavior: 'smooth'
  })
}

// 生命周期钩子
onMounted(() => {
  window.addEventListener('scroll', handleScroll)
})

onUnmounted(() => {
  window.removeEventListener('scroll', handleScroll)
})
</script>

<style scoped lang="scss">
.floating-btn {
  position: fixed;
  right: 30px;
  bottom: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary-blue);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 10px 25px rgba(13, 110, 253, 0.5);
  cursor: pointer;
  transition: var(--transition);
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  visibility: hidden;
  transition: all 0.3s ease;
  
  &:hover {
    transform: scale(1.1);
    background: var(--dark-blue);
  }
  
  &.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
  }
}
</style>
